<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="../css/reset.css">
    <style>
        .title {
            line-height: 40px;
        }

        .list {
            margin-top: 20px;
        }

        .list li {
            height: 32px;
            line-height: 32px;
            border: 1px dashed #333;
        }
    </style>
</head>

<body>
    <div id="wrap">
        <button class="replaceEle">替换元素</button>
        <ul class="list one">
            <li class="first">01</li>
            <li>02</li>
            <li class="mid">03</li>
            <li>04</li>
            <li>05</li>
            <li class="last">06</li>
        </ul>
    </div>
</body>
<script>
    // 节点的替换

    // parent.replaceChild(newEle,oldEle)  由父元素统筹 用一个元素(新的元素/已存在的元素) 替换另一个元素  (喜新厌旧)

    var replaceEle = document.getElementsByClassName("replaceEle")[0];
    var list = document.getElementsByClassName("list")[0];
    var mid = document.getElementsByClassName("mid")[0];

    replaceEle.onclick = function () {
        if (mid) {
            var li = document.createElement("li");
            li.innerText = "我是新增的li";
            li.setAttribute("class", "newLi");
            li.style.backgroundColor = "pink";
            list.replaceChild(li, mid);
            mid = null;
        }
    }









</script>

</html>